#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include <QPushButton>
#include <QIcon>
#include <QLabel>
#include <QPixmap>
#include <QTextEdit>
#include <QFont>
#include <QString>
#include <QFile>
#include <QTextStream>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("学生管理系统");
    this->setWindowIcon(QIcon(":/Picture/Picture/windowTitle.png"));
    this->setFixedSize(600,800);
    QLabel *backgroundLabel = new QLabel;
    backgroundLabel->setFixedSize(600,800);
    QPixmap backgroundPixmap(":/Picture/Picture//background.png");
    backgroundLabel->setPixmap(backgroundPixmap.scaled(backgroundLabel->size(), Qt::KeepAspectRatio));
    this->setCentralWidget(backgroundLabel);
    QFile openfile("AllClassName.txt");
    openfile.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream in(&openfile);
    QString line = in.readLine(); // 读取第一行
    openfile.close(); // 关闭文件
    QString temp1 = "开始对";
    QString temp2 = "班的学生进行管理！";
    QString line1;
    line1 = temp1 + line + temp2;
    //创建对话框以传达提示信息
    QTextEdit* textEdit = new QTextEdit(this);
    textEdit->setReadOnly(true); // 设置文本框为只读
    textEdit->setGeometry(70, 50, 460, 200); // 设置位置和大小
    textEdit->setPlainText(line1); // 设置初始文本
    textEdit->setStyleSheet("QTextEdit { background: transparent;"
                            "border: 2px solid #000000; " //设置边框为2像素宽，黑色
                            "border-radius: 5px; " // 设置边框圆角半径
                            "transition: background-color 0.3s ease; " //添加过渡效果 }"); //设置文本框透明
                            "}");
    QFont font;
    font.setPointSize(18); // 设置字体大小
    font.setFamily("华文新魏"); // 设置字体族
    textEdit->setFont(font); //应用字体到文本框
    //设置功能按钮：初始化/初始信息修改、日常化录入、查询
    QPushButton * first = new QPushButton("初始化/初始信息修改",this);
    first->setFixedSize(240,70);
    first->move(180,320);
    first->setFont(font);
    first->setStyleSheet("QPushButton { "
                            "background-color: transparent; " //设置背景色为透明
                            "border: 2px solid #000000; " //设置边框为2像素宽，黑色
                            "border-radius: 5px; " // 设置边框圆角半径
                            "transition: background-color 0.3s ease; " //添加过渡效果
                            "}"
                            "QPushButton:hover { "
                            "background-color: #ADD8E6; " //鼠标悬停时设置背景色为浅蓝色
                            "}");
    QPushButton * daily = new QPushButton("日常化录入",this);
    daily->setFixedSize(240,70);
    daily->move(180,470);
    daily->setFont(font);
    daily->setStyleSheet("QPushButton { "
                         "background-color: transparent; " //设置背景色为透明
                         "border: 2px solid #000000; " //设置边框为2像素宽，黑色
                         "border-radius: 5px; " // 设置边框圆角半径
                         "transition: background-color 0.3s ease; " //添加过渡效果
                         "}"
                         "QPushButton:hover { "
                         "background-color: #ADD8E6; " //鼠标悬停时设置背景色为浅蓝色
                         "}");
    QPushButton * ask = new QPushButton("查询",this);
    ask->setFixedSize(240,70);
    ask->move(180,620);
    ask->setFont(font);
    ask->setStyleSheet("QPushButton { "
                         "background-color: transparent; " //设置背景色为透明
                         "border: 2px solid #000000; " //设置边框为2像素宽，黑色
                         "border-radius: 5px; " // 设置边框圆角半径
                         "transition: background-color 0.3s ease; " //添加过渡效果
                         "}"
                         "QPushButton:hover { "
                         "background-color: #ADD8E6; " //鼠标悬停时设置背景色为浅蓝色
                         "}");
    FirstWindow* firstWindow = new FirstWindow;
    DailyWindow* dailyWindow = new DailyWindow;
    AskWindow* askWindow = new AskWindow;
    connect(first,&QPushButton::clicked,[=](){
        firstWindow->show();
    });
    connect(daily,&QPushButton::clicked,[=](){
        dailyWindow->show();
    });
    connect(ask,&QPushButton::clicked,[=](){
        askWindow->show();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}
